﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace LabMS.Web.DictionaryMaintenance
{
    public partial class EditDictionary : Base.BasePage
    {
        ExtendBLL.Dictionary ED = new ExtendBLL.Dictionary();
        List<LabMS.Model.Dictionary> MD = new List<LabMS.Model.Dictionary>();

        public string TableName = "";//表名 ：性别
        public string TableDes1 = "";
        public string TableDes2 = "";
        public string DClass = "";//类别名： SEX
        public int ID;

        //public string Code = ""; //1，2
        //public string Name = "";//男，女

        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("ZDWH");
            strPageUserType.Add("mana");
            if (Request.QueryString["ID"] != null)
            {
                ID = int.Parse(Request.QueryString["ID"].ToString());
            }
            if (!IsPostBack)
            {
                InitBind(ID);
            }
        }

        /// <summary>
        /// 根据传过来的ID初始化页面
        /// </summary>
        /// <param name="ID"></param>
        protected void InitBind(int ID)
        {
            string str = "ID=" + ID;
            MD = ED.GetModelList(str);
            tbName.Text = MD[0].Name.ToString();
            tbCode.Text = MD[0].Code.ToString();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region 验证
            if (string.IsNullOrEmpty(tbCode.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "此项不能为空！");
                tbCode.Focus();
            }
            else if (string.IsNullOrEmpty(tbName.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "此项不能为空！");
                tbName.Focus();
            }
            #endregion
            LabMS.Model.Dictionary MD = new LabMS.Model.Dictionary();

            MD.ID = ID;
            MD.DClass = ED.GetListByID(ID)[0].DClass;
            MD.Code = tbCode.Text.Trim();
            MD.Name = tbName.Text.Trim();
         
            try
            {
                ED.Update(MD);
            }
            catch(Exception ex)  
            {
                throw ex;
            }
            Common.JShelper.JSAlertAndRedirect(this.Page, "", "更新成功!", "DictionaryMaintenance.aspx?Name="+Server.HtmlEncode(MD.Name)+"&Code="+Server.HtmlEncode(MD.DClass));
        }
    }
}
